# Python3_GF_Pandas_Specific_Functions.py
# Create By GF 2023-12-19 14:28

# ----------------------------------------------------------------------------------------------------

# GF Pandas Content Wash Cell One By One (Cry = Content).
def PdCry_Wash_Cell_One_By_One(Df:pandas.core.frame.DataFrame):
    
    for RowIdx in Df.index:
        for ColIdx in Df.columns:
            if (type(Df.loc[RowIdx, ColIdx]) is str): 
                Df.loc[RowIdx, ColIdx] = Df.loc[RowIdx, ColIdx].replace(str(' '),  str(''))
                Df.loc[RowIdx, ColIdx] = Df.loc[RowIdx, ColIdx].replace(str('，'), str('/'))
                Df.loc[RowIdx, ColIdx] = Df.loc[RowIdx, ColIdx].replace(str(','),  str('/'))
                Df.loc[RowIdx, ColIdx] = Df.loc[RowIdx, ColIdx].replace(str('\n'), str(''))
                Df.loc[RowIdx, ColIdx] = Df.loc[RowIdx, ColIdx].replace(str('\t'), str(''))
    # ----------------------------------------------
    # Function End.

# GF Pandas Object as Type Integer.
def PdObj_Astype_Int(Obj:object):

    try:
        return int(Obj)
    except AttributeError:
        return Obj
    # ValueError: cannot convert float NaN to integer
    except ValueError:
        return Obj
    # ----------------------------------------------
    # Function End.

# GF Pandas Object's Datetime Strftime.
def PdObj_Datetime_Strftime(Obj:object, Format:str):

    if (type(Obj) is datetime.datetime):
        return Obj.strftime(Format)
    else:
        return Obj
    # ----------------------------------------------
    # Function End.

# ----------------------------------------------------------------------------------------------------
# EOF
